import pygame


class SoundEffect:
    """控制各种音效播放"""

    def __init__(self, stats):
        """初始化各种音效"""
        pygame.mixer.init()
        self.stats = stats
        self.enemy_blast_sound = pygame.mixer.Sound('images_source/enemy_blast.wav')
        self.spacecraft_blast_sound = pygame.mixer.Sound('images_source/spacecraft_blast.mp3')
        self.launch_bullet_sound = pygame.mixer.Sound('images_source/launch_bullet.mp3')
        self.new_record_sound = pygame.mixer.Sound('images_source/new_record.mp3')

    def play_enemy_blast_sound(self):
        """播放敌机爆炸音效"""
        self.enemy_blast_sound.play()

    def play_spacecraft_blast_sound(self):
        """播放飞船爆炸音效"""
        self.spacecraft_blast_sound.play()

    def play_launch_bullet_sound(self):
        """播放子弹发射音效"""
        if self.stats.dictionaries['active']['game_active']:
            self.launch_bullet_sound.play()

    def play_new_record_sound(self, stats):
        """播放得到新纪录音效"""
        if stats.dictionaries['active']['new_record_sound']:
            self.new_record_sound.play()
            stats.dictionaries['active']['new_record_sound'] = False
